var http = require("http");
var bufferhelper=require("bufferhelper");
var iconv=require("iconv-lite");

var r = Math.random();
var actionUrl = "http://www.jubi.com/coin/allcoin?t=" + r;

function getData() {
    http.get(actionUrl, function(res) {

		// console.log(res);
		//res.setEncoding("utf8");
		var _bufferhelper=new bufferhelper();
		var response="";
		res.on("data", function(chunk) {
			//console.log(chunk);
			_bufferhelper.concat(chunk);
			response=response+chunk;
		});
		res.on("end",function(){
		var coinsprices  =JSON.parse(iconv.decode(_bufferhelper.toBuffer(),'GBK'))
		console.log("币种\t\t当前价\t\t买一\t\t卖一\t\t最高\t\t最低\t\t成交量");
	 		for(var coin in coinsprices){
	 			var currentCoin=coinsprices[coin];
	 			console.log("%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s\t\t%s",currentCoin[0],currentCoin[1],currentCoin[2],currentCoin[3],currentCoin[4],currentCoin[5],currentCoin[6]);
	 		}
		})
	});
}
getData();